package com.ljf.task.infra.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.infra.repository.impl.BasisRepositoryImpl;
import com.ljf.common.utils.CollectionUtil;
import com.ljf.common.utils.EnumUtil;
import com.ljf.common.utils.StringUtil;
import com.ljf.task.domain.repository.TaskDatTaskTabulationRepository;
import com.ljf.task.dto.query.TaskDatTaskTabulationQuery;
import com.ljf.task.enums.TaskDatTaskTabulationTaskStatusEnum;
import com.ljf.task.enums.TaskDatTaskTabulationTaskTypeEnum;
import com.ljf.task.infra.mapper.TaskDatTaskTabulationMapper;
import com.ljf.task.model.TaskDatTaskTabulation;
import com.ljf.task.vo.TaskDatTaskTabulationVO;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 任务列表  数据访问接口实现
 *
 * @author LJF
 * @since 2024-12-25
 */
@Component
public class TaskDatTaskTabulationRepositoryImpl extends BasisRepositoryImpl<TaskDatTaskTabulationMapper, TaskDatTaskTabulation, TaskDatTaskTabulationQuery, TaskDatTaskTabulationVO> implements TaskDatTaskTabulationRepository {

    @Override
    protected QueryWrapper<TaskDatTaskTabulation> fillWrapper(TaskDatTaskTabulationQuery query, boolean sort) throws ServiceException {
        QueryWrapper<TaskDatTaskTabulation> wrapper = super.fillWrapper(query, sort);
        if (CollectionUtil.isNotEmpty(query.getCodeList())) {
            wrapper.in(TaskDatTaskTabulation.COL_CODE, query.getCodeList());
        }
        if (StringUtil.isNotEmpty(query.getTitleLike())) {
            wrapper.like(TaskDatTaskTabulation.COL_TITLE, query.getTitleLike());
        }
        if (StringUtil.isNotEmpty(query.getMenuCodeRightLike())) {
            wrapper.likeRight(TaskDatTaskTabulation.COL_MENU_CODE, query.getMenuCodeRightLike());
        }
        return wrapper;
    }

    @Override
    protected void fillInfo(List<TaskDatTaskTabulationVO> resultList) throws ServiceException {
        super.fillInfo(resultList);
        if (CollectionUtil.isEmpty(resultList)) {
            return;
        }
        Map<Integer, String> taskStatusMap = EnumUtil.getCodeToNameMap(TaskDatTaskTabulationTaskStatusEnum.values());
        Map<Integer, String> taskTypeMap = EnumUtil.getCodeToNameMap(TaskDatTaskTabulationTaskTypeEnum.values());
        for (TaskDatTaskTabulationVO result : resultList) {
            result.setTaskStatusName(taskStatusMap.get(result.getTaskStatus()));
            result.setTaskTypeName(taskTypeMap.get(result.getTaskType()));
        }
    }

}
